<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Category as CategoryModel;
use fast\Tree;

/**
 * 分类接口
 */
class Category extends Api
{


	// 无需登录的接口,*表示全部
	protected $noNeedLogin = ['*'];

	protected $model = null;
	protected $categorylist = [];
	
	

    public function index()
    {
		 $this->model = model('app\common\model\Category');  //或者使用助手函数`model` 
		 
		 $tree = Tree::instance();
		 //dump($tree);
		 
		 $tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
		 //dump($tree);
		 
		 $this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
		 //dump($this->categorylist);
		 
		 $categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
		 //dump($categorydata);
		 foreach ($this->categorylist as $k => $v) {
		 	
		     $categorydata[$v['id']] = $v;
		 }
		 dump($categorydata);
		 $typeList = CategoryModel::getTypeList();
		 //dump($typeList);
	
		
         $this->success('返回成功',["flagList"=>$this->model->getFlagList(),"typeList"=>$typeList,"parentList"=>$categorydata]);
    }


}
